﻿using System;
using System.Collections.Generic;
using System.Linq;

using System.Data;
using Prodma.DataAccess.Database;
using Prodma.DataAccess.Interfaces.Models;
using Prodma.DataAccess.Models.ViewModels;
using Prodma.DataAccess.Helper.Enumerators;
using System.Configuration;
using Prodma.DataAccess.Models;
using System.Web.Security;

namespace Prodma.DataAccess.DataService
{
    public class FilterParametersService 
    {

        private DataContext context = new DataContext();

        public void SaveParameters(tb_FilterParameters parameters)
        {
            using (context)
            {
                var edit = (from param in context.tb_FilterParameters
                            where param.UserID == parameters.UserID
                            select param).FirstOrDefault();

                if (edit != null)
                {
                    edit.KategoriID = parameters.KategoriID;
                    edit.MarkaID = parameters.MarkaID;
                    edit.ModelID = parameters.ModelID;
                }
                else
                {
                    context.AddTotb_FilterParameters(parameters);
                }
                context.SaveChanges();
            }
        }

        public tb_FilterParameters GetFilterParameters(int userId)
        {
            using (context)
            {
                var parameters = (from prms in context.tb_FilterParameters
                                  where prms.UserID == userId
                                  select prms).SingleOrDefault();

                return parameters;
            }
        }
    }
}
